#if !defined(BindHeader)
#define BindHeader

#include "node.h"
#include "trail.h"

class Binder {
public:
  Binder () {
  }
  Binder (Trail::Pointer s) :
    state (s) {
  }

  // Captures initial state of the trail
  // (so we can backtrack to that point later)
  void capture (Trail &trail) {
    state = trail.state ();
  }

  bool bind (Node &e1, Node &e2, Trail &trail) {
    bool ret = bindDoNotRollback (&e1, &e2, trail);
    if(!ret)
      undo (trail);
    return ret;
  }

  bool bindDoNotRollback (pNode, pNode, Trail&);

  // The backtracker undo all previous binds
  void undo (Trail &trail) {
    trail.rollback (state);
  }

  Trail::Pointer state;
};

#endif
